<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div :class="!is_showselother ? 'pagetop' : 'pagetopother'">
            <div style="width: 100%">
                <div style="float: left; width: 100%">
                    <table style="font-size: 12px; white-space: nowrap; width: 100%" class="table1style" border="0">
                        <col style="width: 6%" />
                        <col style="width: 13%" />
                        <col style="width: 1%" />
                        <col style="width: 13%" />
                        <col style="width: 6%" />
                        <col style="width: 9%" />
                        <col style="width: 6%" />
                        <col style="width: 9%" />
                        <col style="width: 8%" />
                        <col style="width: 9%" />
                        <col style="width: 8%" />
                        <col style="width: 9%" />
                        <tr>
                            <td align="right">退回时间</td>
                            <td>
                                <el-date-picker v-model="reject_startdt" :clearable="true" type="date" placeholder="选择日期"
                                    value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                            </td>
                            <td>至</td>
                            <td>
                                <el-date-picker v-model="reject_enddt" type="date" :clearable="true" placeholder="选择日期"
                                    value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                            </td>
                            <td align="right">条码编号</td>
                            <td>
                                <el-input v-model.trim="txtbarcode" @keyup.enter.native="InitPage" clearable
                                    style="width: 120px"></el-input>
                            </td>

                            <td align="right">病人姓名</td>
                            <td>
                                <el-input v-model.trim="txtpatname" clearable @keyup.enter.native="InitPage"
                                    style="width: 120px"></el-input>
                            </td>
                            <td align="right">申请科室</td>
                            <td>
                                <rm-ddl-common @change="deptchange" datatype="dept" dataname="科室" v-model="txtdept"
                                    width="100%"></rm-ddl-common>
                            </td>
                            <td align="right">所属病区</td>
                            <td>
                                <rm-ddl-common :appendtobody="true" @change="wardchange" datatype="ward" dataname="病区"
                                    v-model="txtward" width="100%"></rm-ddl-common>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">退回原因</td>
                            <td colspan="3">
                                <el-autocomplete class="inline-input" v-model.trim="txtrejReason"
                                    :fetch-suggestions="querySearch" placeholder="请输入内容" @select="handleSelect"
                                    style="width: 100%" clearable></el-autocomplete>
                            </td>
                            <td align="right">退回用户</td>
                            <td>
                                <rm-ddl-common @change="userinfochange" datatype="userinfo" dataname="用户" v-model="txtuser"
                                    width="120px"></rm-ddl-common>
                            </td>
                            <td align="right">病&nbsp;&nbsp;历&nbsp;&nbsp;号</td>
                            <td>
                                <el-input v-model.trim="txtpatno" @keyup.enter.native="InitPage" clearable
                                    style="width: 120px"></el-input>
                            </td>
                            <td align="right">送检医院</td>
                            <td>
                                <rm-ddl-common @change="hospitalchange" datatype="hospital" dataname="医院"
                                    v-model="txthoscode" width="100%"></rm-ddl-common>
                            </td>
                            <td align="right">执行科室</td>
                            <td>
                                <rm-ddl-common @change="performdeptchange" datatype="dept" dataname="科室"
                                    v-model="txtperformdept" width="100%"></rm-ddl-common>
                            </td>
                        </tr>
                        <tr v-show="is_showselother">
                            <td align="right">签收日期</td>
                            <td>
                                <el-date-picker v-model="rcv_startdt" clearable type="date" placeholder="选择日期"
                                    value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                            </td>
                            <td>至</td>
                            <td>
                                <el-date-picker v-model="rcv_enddt" type="date" clearable placeholder="选择日期"
                                    value-format="yyyy-MM-dd" style="width: 100%"> </el-date-picker>
                            </td>
                            <td align="right">分单类别</td>
                            <td>
                                <rm-ddl-common @change="reqgroupchange" datatype="reqgroup" dataname="分单类别"
                                    v-model="txtreqgroup" width="120px"></rm-ddl-common>
                            </td>
                            <td align="right">标本类型</td>
                            <td>
                                <rm-ddl-common ref="ddlspecimen" @change="specimenchange" datatype="specimen"
                                    dataname="标本类型" v-model="txtspecimen" width="120px"></rm-ddl-common>
                            </td>

                            <td align="right">退回人所属组</td>
                            <td>
                                <rm-ddl-common @change="labgroupchange1" datatype="labgroup" dataname="检验工作组"
                                    v-model="txtusergroup" width="100%"></rm-ddl-common>
                            </td>
                            <td align="right">条码所属组</td>
                            <td>
                                <rm-ddl-common @change="labgroupchange2" datatype="labgroup" dataname="检验工作组"
                                    v-model="txtbarcodegroup" width="100%"></rm-ddl-common>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="12" style="padding-right: 200px; text-align: right">
                                <el-link :underline="false" @click="btn_showselother">{{ is_showselother ? "收起其它条件" :
                                    "展开其它条件" }}<i
                                        :class="is_showselother ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"></i></el-link>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="operation-list">
                    <el-button icon="el-icon-search" @click="InitPage" type="primary">查询</el-button>
                    <el-button icon="el-icon-sort" @click="btnSort">排序</el-button>
                    <el-button icon="el-icon-close" @click="btnClear">清除</el-button>
                    <el-button icon="el-icon-printer" @click="btnPrint($event)">打印</el-button>
                    <el-button @click="setExportColumn">导出列设置</el-button>
                    <el-button icon="el-icon-upload2" @click="btnExport">导出</el-button>
                    <!-- <el-button icon="el-icon-picture" @click.native="BtnLookPic">查看照片</el-button> -->
                </div>
            </div>
        </div>
        <div :class="!is_showselother ? 'pagecenter' : 'pagecenterother'">
            <div class="middle-center">
                <vxe-table show-overflow ref="xTable1" :height="!is_showselother ? 'auto' : '100%'" row-id="id"
                    :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" :keyboard-config="keyConfig"
                    :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false, activeMethod: activecell }"
                    :keyboard-local-config="keyLocalConfig" :data.sync="tableData1" border size="mini" show-header-overflow
                    highlight-current-row highlight-hover-row resizable stripe @current-change="currentChange"
                    :loading="loading1" class="myclass" @cell-dblclick="cellDblClick">
                    <vxe-table-column type="index" title="No." width="35" align="center"></vxe-table-column>
                    <vxe-table-column field="isPhoto" title="图片" width="35" align="center" header-align="center">
                        <template v-slot="{ row }">
                            <div v-show="row.isPhoto != '0'">
                                {{ row.isPhoto }}<i class="el-icon-picture" style="padding: 2px !important"></i>
                            </div>
                        </template>
                    </vxe-table-column>
                    <vxe-table-column field="barcode" title="条码号" width="107" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="pat_no" title="病人号" width="105" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="pat_name" title="姓名" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_deptno" title="申请科室" width="114" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="labgroup" title="检验组" width="100" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="usergroup" title="退回人工作组" width="100" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_wardno" title="病人病区" width="115" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_bedno" title="床号" width="64" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="reject_user" title="退回人" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="reject_dt" title="退回时间" width="138" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="reject_reason" title="退回原因" width="205" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="reject_memo" title="退回备注" width="205" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="sampled_dt" title="采样时间" width="138" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="sampled_user" title="采样人" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="recieve_dt" title="检验科接收时间" width="106" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="recieve_user" title="检验科接收人" width="103" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="tellman" title="临床通知人" width="92" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="hischkdt" title="临床确认时间" width="138" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="hischkman" title="确认人" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="description" title="确认备注" width="205" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="specimen_name" title="标本类型" width="84" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="emer_flag" title="加急" width="56" header-align="center" sortable>
                    </vxe-table-column>
                    <vxe-table-column field="req_groupna" title="分单类别简称" width="116" header-align="center" sortable>
                    </vxe-table-column>
                    <vxe-table-column field="sample_items" title="项目描述" width="203"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="req_stat" title="申请状态" width="82" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_dt" title="申请日期" width="125" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_docname" title="申请人" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="pat_sex" title="性别" width="50" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="recieve1_dt" title="签收时间" width="138" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="recieve1_user" title="签收人" width="60" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="pat_id" title="病人唯一号" width="107" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_birth" title="病人生日" width="100" header-align="center"
                        align="center"></vxe-table-column>
                    <vxe-table-column field="pat_agestr" title="年龄字串" width="78" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="pat_typename" title="病人类型" width="77" header-align="center" align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="specimen_code" title="标本类型" width="84" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="req_comm" title="医生备注" width="197" header-align="center"></vxe-table-column>
                    <vxe-table-column field="pat_phone" title="联系电话" width="100" header-align="center"></vxe-table-column>
                    <vxe-table-column field="perform_dept" title="执行科室" width="114" header-align="center"
                        sortable></vxe-table-column>
                    <vxe-table-column field="hospcode" title="送检医院" width="123" header-align="center"></vxe-table-column>
                    <vxe-table-column field="amount" title="金额" width="80" header-align="center" align="right"
                        sortable></vxe-table-column>
                    <vxe-table-column field="sample_detail" title="标本备注说明 " width="121"
                        header-align="center"></vxe-table-column>
                    <vxe-table-column field="rej_cnt" title="退回次数 " width="60" header-align="center"></vxe-table-column>
                    <!-- <vxe-table-column field="req_groupid" title="分单类别ID" width="100" header-align="center">
                    </vxe-table-column> -->
                </vxe-table>
                <div class="table-bottom">
                       <div
                            style="font-size: 17px; padding-left: 3px; background-color: #fff; overflow: auto; text-align: center">
                            <span style="font-weight: bold; margin-left: 18px; color: red">合计金额：￥{{ amountSum1 }}</span>
                        </div>
                    </div>
            </div>
            <div class="middle-right">
                <rm-layout-top splitcolor="white" :splitwidth="5" :fixsize="300">
                    <template v-slot:fix>
                        <div style="height: 100%;">
                            <vxe-table show-overflow border ref="xTable2" :height="!is_showselother ? 'auto' : '100%'"
                                row-id="id" size="mini" :select-config="{ reserve: true }" :data.sync="tableData2"
                                show-header-overflow highlight-current-row highlight-hover-row resizable stripe
                                :loading="loading2" status-msg-group="none" class="myclass">
                                <vxe-table-column field="seq" title="序号" width="50" header-align="center"
                                    align="center"></vxe-table-column>
                                <vxe-table-column field="req_itemname" title="申请项目名称" width="166"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="item_price" title="实际价格" width="88" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="qty" title="数量" width="57" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="amount" title="金额" width="57" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="req_itemcode" title="申请项目代码" width="119" header-align="center"
                                    align="center"></vxe-table-column>
                                <vxe-table-column field="his_itemcode" title="HIS原始项目代码" width="131" header-align="center"
                                    align="center"></vxe-table-column>
                                <vxe-table-column field="his_recordid" title="HIS中对应记录号" width="129"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="combitemna" title="所属组合项目简称" width="127"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="base_price" title="理论/区域价格" width="104" header-align="center"
                                    align="right"></vxe-table-column>
                                <vxe-table-column field="stat_flag" title="统计标志" width="79"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="other_flag" title="其它标志" width="79"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="status" title="状态" width="58"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="lab_add" title="实验室添加标志" width="113"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="add_dt" title="添加时间" width="92" header-align="center"
                                    :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                <vxe-table-column field="add_user" title="添加用户" width="97"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="req_groupid" title="分单类别ID" width="97"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="charge_flag" title="计价标志" width="82"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="his_refcol1" title="HIS表相关字段1" width="137"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="his_refcol2" title="HIS表相关字段2" width="137"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="his_refcol3" title="HIS表相关字段3" width="137"
                                    header-align="center"></vxe-table-column>
                                <vxe-table-column field="reportid" title="报告ID" width="80"
                                    header-align="center"></vxe-table-column>
                            </vxe-table>
                            <div class="table-bottom">
                                <div
                                    style="font-size: 17px; padding-left: 3px; background-color: #fff; overflow: auto; text-align: center">
                                    <span style="font-weight: bold; margin-left: 18px; color: blue">合计金额：￥{{ amountSum2
                                    }}</span>
                                </div>
                            </div>
                        </div>
                    </template>
                    <div style="height: 100%; width: 100%;">
                        <el-tabs style="height: 100%" type="border-card" v-model="tab_showflag" @tab-click="tabclick_Event">
                            <el-tab-pane label="操作日志" name="operatelog">
                                <vxe-table :data.sync="tableDatalog" :loading="loadinglog"
                                    :tree-config="{ children: 'children', expandAll: false }"
                                    :select-config="{ labelField: 'log_content' }" :fit="false" @cell-dblclick="LogDblClick"
                                    :cell-class-name="ColumnClassName" height="auto" highlight-current-row
                                    highlight-hover-row resizable header-align="center" show-overflow="tooltip"
                                    show-header-overflow="tooltip" size="mini" border stripe column-width="100px"
                                    ref="tablelog">
                                    <vxe-table-column field="log_date" title="操作日期" width="120px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="trans_type" title="操作类型" width="80px" align="center"
                                        :formatter="['formatSelectList', reqstatOptiontable]"></vxe-table-column>
                                    <vxe-table-column field="log_content" title="操作内容" width="220px" tree-node>
                                        <template v-slot="{ row }">
                                            <div style="max-width: 180px; display: inline-block">{{ row.log_content }}</div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="username" title="操作者" width="100px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="ref_user" title="相关人" width="100px"></vxe-table-column>
                                    <vxe-table-column field="labgroupid" title="工作组" width="100px"></vxe-table-column>
                                    <vxe-table-column field="computer_name" title="操作时机器名" width="100px">
                                        <template v-slot="{ row }">
                                            <span style="color:blue;">{{ row.computer_name }}</span>
                                            <i class="el-icon-refresh" @click="repalceComputerName(row)"></i>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="mac_address" title="操作时机器MAC" width="100px"></vxe-table-column>
                                    <vxe-table-column field="syncflag" title="同步HIS标志" width="100px"></vxe-table-column>
                                    <vxe-table-column field="synctime" title="同步时间" width="100px"></vxe-table-column>
                                    <vxe-table-column field="syncerrtext" title="同步失败信息" width="100px"></vxe-table-column>
                                </vxe-table>
                            </el-tab-pane>
                            <el-tab-pane label="图片" name="picture">
                                <el-carousel trigger="click" style="height: 100%; width: 100%;" height="100%"
                                    :autoplay="false">
                                    <el-carousel-item v-for="(item, i) in LPicData" :key="i">
                                        <div style="height: 100%; width: 100%;">
                                            <el-image :src="item" @click="onPreview(item)"
                                                style=" width: 100%; height: 99%;"></el-image>
                                        </div>
                                    </el-carousel-item>
                                </el-carousel>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                </rm-layout-top>
            </div>
        </div>
        <el-dialog title="EXCEL导出" :visible.sync="dialogVisible" width="30%">
            <el-checkbox-group v-model="checkList">
                <div style="font-size: 16px">
                    <el-checkbox label="1">导出结果信息</el-checkbox>
                </div>
                <div style="font-size: 16px">
                    <el-checkbox label="2">导出结果明细</el-checkbox>
                </div>
            </el-checkbox-group>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="startExport">导 出</el-button>
                <el-button @click="dialogVisible = false">取 消</el-button>
            </span>
        </el-dialog>
        <!-- <el-dialog title="图形/图片文件查看" :visible.sync="PhotoDialogVisible" width="500px">
            <div style="height: 400px; width: 100%">
                <div style="border: 1px solid #ccc">
                    <div class="demo-image__placeholder">
                        <div class="block" style="width: 100%">
                            <span class="demonstration">{{ LPicName }}({{ LPicTime }})</span>
                            <el-image :src="LPicData" style="width: 400px; height: 300px"></el-image>
                        </div>
                    </div>
                </div>
            </div>
        </el-dialog> -->
        <!--导出列选择-->
        <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog
            :close-on-click-modal="false" v-if="chooseColumndialogVisible">
            <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn"
                ref="excolset"></rm-excolsetting>
        </el-dialog>
        <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogDetailVisible"
            title="检验报告修改详细内容" top="5vh" width="800px">
            <vxe-table :data.sync="tableDataRptLogDetail" ref="xTableRptLog" height="400px" :loading="RptLogDetailloading"
                :sort-config="{ trigger: 'cell' }" show-overflow border size="mini" show-header-overflow
                highlight-current-row highlight-hover-row resizable stripe>
                <vxe-table-column field="rpt_logid" title="日志明细ID" width="100" sortable
                    header-align="center"></vxe-table-column>
                <vxe-table-column field="objecttype" title="修改类型" width="100" sortable
                    header-align="center"></vxe-table-column>
                <vxe-table-column field="columnname" title="修改对象" width="160" sortable
                    header-align="center"></vxe-table-column>
                <vxe-table-column field="oldvalue" title="修改/复查前取值" width="160" sortable
                    header-align="center"></vxe-table-column>
                <vxe-table-column field="newvalue" title="修改/复查后取值" width="160" sortable
                    header-align="center"></vxe-table-column>
            </vxe-table>
        </el-dialog>
        <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset"
            v-show="false"></rm-excolsetting>
        <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="viewerList" />
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
import ElImageViewer from '../../../../element-ui/packages/image/src/image-viewer';
XEUtils.mixin({
    // 自定义全局的格式化处理函数
    formatSelectList(cellValue, list) {
        let item = list.find((item) => item.data == cellValue);
        return item ? item.display : "";
    },
});
export default {
    name: "LIS218",
    components: { RmExcolsetting, ElImageViewer },
    data() {
        return {
            loading1: false,
            loading2: false,
            dialogVisible: false,
            checkList: ["1"],
            reject_startdt: this.$pub.InitDate(),
            reject_enddt: this.$pub.InitDate(),
            txtbarcode: "",
            txtpatno: "",
            txtpatname: "",
            txtdept: "",
            txtward: "",
            txtrejReason: "",
            Reason: "",
            txtuser: "",
            rcv_startdt: "",
            rcv_enddt: "",
            txtreqgroup: "",
            txtspecimen: "",
            txthoscode: "",
            txtusergroup: "",
            txtbarcodegroup: "",
            txtperformdept: "",
            tableData1: [],
            tableData2: [],
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: false,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            sortArr: [],
            tableColumn: [],
            tableColumn1: [],
            tableColumn2: [],
            RejReaSonOption: [],
            patSexOption: [
                { label: "", value: "" },
                { label: "男", value: "1" },
                { label: "女", value: "2" },
            ],
            reqstatOption: [],
            specimenOPtion: [],
            userOption: [],
            patTypeOPtion: [],
            is_showselother: false,
            userno: this.$tool.getSession(this.$tool.loginuserno),
            ReqBackstyleid2: "",
            PhotoDialogVisible: false,
            key_barcode: "",
            currow: {},
            // LPicData: "",
            LPicTime: "",
            LPicName: "",
            arrLPicData: [],
            allTableCol: [],
            chooseColumndialogVisible: false,
            excolPro: "lis218",
            exportTableColLen: 0,
            deptname: "",
            performdeptname: "",
            wardname: "",
            username: "",
            hosname: "",
            usergroupname: "",
            barcodegroupname: "",
            reqgroupname: "",
            specimenname: "",
            showViewer: false,
            viewerList: [],
            LPicData: [],
            tab_showflag: "operatelog",
            tableDatalog: [],
            loadinglog: false,
            reqstatOptiontable: [],
            dialogDetailVisible: false,
            tableDataRptLogDetail: [],
            RptLogDetailloading: false,
        };
    },
    created() {
        this.reject_startdt = this.$pub.InitDate();
        this.reject_enddt = this.$pub.InitDate();
        this.initOption(); //初始化下拉框的数据
        //this.InitPage(); //初始化主列表
    },
    mounted() {
        this.$refs.excolset.colSettingToDB();
    },
    updated() { },
    computed: {
        amountSum1() {
            return XEUtils.sum(this.tableData1, "amount");
        },
        amountSum2() {
            return XEUtils.sum(this.tableData2, "amount");
        },
    },
    methods: {
        InitPage() {
            this.loading1 = true;
            this.LPicData = [];
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS218",
                    method: "post",
                    data: {
                        action: "InitPage",
                        reject_startdt: this.reject_startdt,
                        reject_enddt: this.reject_enddt,
                        txtbarcode: this.txtbarcode,
                        txtpatno: this.txtpatno,
                        txtpatname: this.txtpatname,
                        txtdept: this.txtdept,
                        txtward: this.txtward,
                        txtrejReason: this.txtrejReason,
                        txtuser: this.txtuser,
                        rcv_startdt: this.rcv_startdt,
                        rcv_enddt: this.rcv_enddt,
                        txtreqgroup: this.txtreqgroup,
                        txtspecimen: this.txtspecimen,
                        txthoscode: this.txthoscode,
                        txtusergroup: this.txtusergroup,
                        txtbarcodegroup: this.txtbarcodegroup,
                        txtperformdept: this.txtperformdept,
                        sortArr: this.sortArr,
                    },
                })
                .then((res) => {
                    if (res.data.length > 0) {
                        this.tableData1 = res.data;
                        this.$refs.xTable1.setCurrentRow(res.data[0]);
                        this.key_barcode = res.data[0].barcode;
                        this.currow = res.data[0];
                        this.getdetails(res.data[0]);
                    } else {
                        this.$refs.xTable1.setCurrentRow(null);
                        this.tableData1 = [];
                        this.tableData2 = [];
                    }
                    this.loading1 = false;
                })
                .catch((err) => {
                    this.loading1 = false;
                });
        },
        tabclick_Event(tab, event) {
            if (tab.name == "operatelog") {
                this.QueryLog(this.key_barcode);
            } else {
                this.getImage(this.currow);
            }
        },
        LogDblClick({ row, rowIndex }) {
            if (row.hasOwnProperty("rpt_logid")) {
                this.QueryLogDetail(row.rpt_logid);
                this.dialogDetailVisible = true;
            }
        },
        QueryLogDetail(logid) {
            this.RptLogDetailloading = true;
            this.$tool
                .request({
                    url: "/ucent/reportlog",
                    method: "post",
                    data: {
                        action: "getReportlogdetail",
                        rpt_logid: logid,
                    },
                })
                .then((res) => {
                    if (res.errcode == "1") {
                        this.tableDataRptLogDetail = res.Data;
                    }
                    this.RptLogDetailloading = false;
                });
        },
        ColumnClassName({ seq, row, rowIndex, $rowIndex, column }) {
            if (column.property == "trans_type") {
                if (row.trans_type == "报告日志" || row.trans_type == "无纸化") return "reportlogclass";
            }
        },
        repalceComputerName(row) {
            this.$pub.getComputerName(row.mac_address)
                .then((name) => {
                    row.computer_name = name;
                })
                .catch(() => {
                    this.$message.error("机器名称查询失败！");
                    //保持原样
                });
        },
        QueryLog(barcode) {
            this.tableDatalog = [];
            this.loadinglog = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS218",
                    method: "post",
                    data: {
                        action: "querylog",
                        barcode: barcode,
                    },
                })
                .then((res) => {
                    this.tableDatalog = this.DealLog(res);
                    this.loadinglog = false;
                })
                .catch((err) => {
                    this.loadinglog = false;
                });
        },
        DealLog(res) {
            var data = res.Data.Data;
            var rptlogdt = res.reportlogdt;
            var bactlogdt = res.bactlogdt;
            var redata = [];
            for (let i = 0; i < data.length; i++) {
                if (data[i].reportid) {
                    var children = rptlogdt.filter((item) => item.reportid == data[i].reportid);
                    if (children.length > 0) data[i].children = children;
                }
                if (data[i].sampleid && data[i].trans_type == '-43') {
                    if (bactlogdt && bactlogdt.length > 0) {
                        data[i].children = bactlogdt;
                    }
                }
                redata.push(data[i]);
            }
            return redata;
        },
        btnSort() {
            if (this.tableColumn.length == 0) {
                let columns = this.$refs.xTable1.getColumns();
                columns.forEach((item) => {
                    this.tableColumn.push({ title: item.title, field: item.property });
                });
            }
            this.$rmsort(
                { tableColumn: this.tableColumn, sortArr: this.sortArr },
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            )
                .then((res) => {
                    this.sortArr = res.data;
                    this.InitPage();
                })
                .catch(() => { });
        },
        btnClear() {
            this.reject_startdt = this.$pub.InitDate();
            this.reject_enddt = this.$pub.InitDate();
            this.txtbarcode = " ";
            this.txtpatno = " ";
            this.txtpatname = " ";
            this.txtdept = " ";
            this.txtward = " ";
            this.txtrejReason = " ";
            this.txtuser = " ";
            this.rcv_startdt = " ";
            this.rcv_enddt = " ";
            this.txtreqgroup = " ";
            this.txtspecimen = " ";
            this.txthoscode = " ";
            this.txtusergroup = " ";
            this.txtbarcodegroup = " ";
            this.txtperformdept = "";
            this.tableData1 = [];
            this.tableData2 = [];
            this.sortArr = [];
        },
        btnPrint(e) {
            if (!this.ReqBackstyleid2) {
                this.$alert("请在申请、采血本地选项页面打印样式中选择退回清单格式！");
                return false;
            }
            let dbtype = this.$ddldata.DbType;
            if (e.shiftKey) {
                //调整
                //
                let sql = "select top 1 1 as 条数,'1' as 序号,* from req_master_all_reject_name";
                if (dbtype == "2") {
                    sql = "select  1 as 条数, '1' as 序号,* from req_master_all_reject_name  limit 1";
                }
                else if (dbtype == "3") {
                    sql = "select 1 as 条数,'1' as 序号, req_master_all_reject_name.*  from req_master_all_reject_name where rownum = 1";
                }
                this.$pub.printlistbill(this, sql, "3", this.ReqBackstyleid2, "退回清单样式", "");
            } else {
                //打印
                let data = this.$refs.xTable1.getTableData().fullData;
                if (data.length > 0) {
                    let barcode = "";
                    data.forEach((item) => {
                        if (barcode == "") {
                            barcode = item.barcode;
                        } else {
                            barcode = barcode + "','" + item.barcode;
                        }
                    });
                    let sql = "select row_number() over (order by 条码号) as 序号,* from req_master_all_reject_name where 条码号 in ('" + barcode + "')";
                    if (dbtype == "2") {
                        sql = "select  @rownum:=@rownum+1 as 序号, req_master_all_reject_name.* from (select @rownum:=0) r, req_master_all_reject_name  where req_master_all_reject_name.条码号 in ('" + barcode + "')";
                    }
                    else if (dbtype == "3") {
                        sql = "select  rownum as 序号,req_master_all_reject_name.* from req_master_all_reject_name where req_master_all_reject_name.条码号 in ('" + barcode + "')";
                    }
                    this.$pub.printlistbill(this, sql, "1", this.ReqBackstyleid2, "退回清单样式", "");
                } else {
                    this.$alert("打印失败，未能获取到数据！");
                }
            }
        },
        btnExport() {
            this.checkList = ["1"];
            this.dialogVisible = true;
        },
        startExport() {
            if (this.checkList.indexOf("1") > -1) {
                let filtertxt = this.getExportFilter();
                let data = this.getExportData("1");
                this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS218标本退回记录查询 result.xlsx", filtertxt);
            }
            if (this.checkList.indexOf("2") > -1) {
                let filtertxt = this.getExportFilter();
                let data = this.getExportData("2");
                this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS218标本退回记录查询 detail.xlsx", filtertxt);
            }
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = "";
            let rejectdttxt = "";
            if (this.reject_startdt) rejectdttxt += XEUtils.toDateString(this.reject_startdt, "yyyy-MM-dd");
            if (this.reject_enddt) rejectdttxt += "至" + XEUtils.toDateString(this.reject_enddt, "yyyy-MM-dd");
            if (rejectdttxt) filtertxt += "退回时间:" + rejectdttxt + "; ";
            if (this.txtbarcode) filtertxt += "条码编号:" + this.txtbarcode + "; ";
            if (this.txtpatname) filtertxt += "病人姓名:" + this.txtpatname + "; ";
            if (this.txtdept) filtertxt += "申请科室:" + this.deptname + "; ";
            if (this.txtward) filtertxt += "所属病区:" + this.wardname + "; ";
            if (this.txtrejReason) filtertxt += "退回原因:" + this.txtrejReason + "; ";
            if (this.txtuser) filtertxt += "退回用户:" + this.username + "; ";
            if (this.txtpatno) filtertxt += "病历号:" + this.txtpatno + "; ";
            if (this.txthoscode) filtertxt += "送检医院:" + this.hosname + "; ";
            if (this.txtperformdept) filtertxt += "执行科室:" + this.performdeptname + "; ";
            let rcvdttxt = "";
            if (this.rcv_startdt) rcvdttxt += XEUtils.toDateString(this.rcv_startdt, "yyyy-MM-dd");
            if (this.rcv_enddt) rcvdttxt += "至" + XEUtils.toDateString(this.rcv_enddt, "yyyy-MM-dd");
            if (rcvdttxt) filtertxt += "签收日期:" + rcvdttxt + "; ";
            if (this.txtreqgroup) filtertxt += "分单类别:" + this.reqgroupname + "; ";
            if (this.txtspecimen) filtertxt += "标本类型:" + this.specimenname + "; ";
            if (this.txtusergroup) filtertxt += "退回人所属组:" + this.usergroupname + "; ";
            if (this.txtbarcodegroup) filtertxt += "条码所属组:" + this.barcodegroupname + "; ";
            return filtertxt;
        },
        getExportData(index) {
            let datas = [];
            let columns = [];
            let tableColumn = [];
            if (index == "1") {
                datas = this.$refs.xTable1.getTableData().fullData;
                this.tableColumn1 = [];
                var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
                tableColumn = this.$refs.xTable1.getColumns();
                if (rightlocalStorage && rightlocalStorage.length > 0) {
                    rightlocalStorage.forEach((item) => {
                        this.tableColumn1.push({
                            title: item.extitle ? item.extitle : item.title,
                            field: item.property,
                        });
                    });
                } else {
                    tableColumn.forEach((item) => {
                        this.tableColumn1.push({ title: item.title, field: item.property });
                    });
                }
                this.exportTableColLen = this.tableColumn1.length;
                columns = this.tableColumn1.filter((item) => item.field);
                let headers = [columns.map((item) => item.title)];
                return headers.concat(
                    datas.map((row) => {
                        return columns.map((column) => {
                            return row[column.field];
                        });
                    })
                );
            } else {
                datas = this.$refs.xTable2.getTableData().fullData;
                if (this.tableColumn2.length == 0) {
                    tableColumn = this.$refs.xTable2.getColumns();
                    tableColumn.forEach((item) => {
                        this.tableColumn2.push({ title: item.title, field: item.property });
                    });
                }
                this.exportTableColLen = this.tableColumn2.length;
                columns = this.tableColumn2.filter((item) => item.field);
                let headers = [columns.map((item) => item.title)];
                return headers.concat(
                    datas.map((row) => {
                        return columns.map((column) => {
                            return row[column.field];
                        });
                    })
                );
            }
        },
        currentChange({ row, column }) {
            this.LPicData = [];
            this.tableDatalog = [];
            if (row) {
                this.key_barcode = row.barcode;
                this.currow = row;
                this.getdetails(row);
            } else {
                this.key_barcode = "";
                this.currow = {};
            }
        },
        cellDblClick({ row, column }) {
            if (column.property == "isPhoto") {
                this.tab_showflag = "picture";
                this.getImage(row);
            }
        },
        onPreview(imgList) {
            this.viewerList = [imgList];
            this.showViewer = true
        },
        closeViewer() {
            this.viewerList = [];
            this.showViewer = false
        },
        initOption() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS218",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                })
                .then((res) => {
                    // this.patTypeOPtion = res.data5;
                    // this.userOption = res.data4;
                    // this.reqstatOption = res.data3;
                    this.RejReaSonOption = res.data2;
                    //this.specimenOPtion = res.data1;
                    this.ReqBackstyleid2 = res.ReqBackstyleid;
                    if (res.reqstat) {
                        res.reqstat.forEach((item) => {
                            this.reqstatOptiontable.push(item);
                        });
                        this.reqstatOptiontable.push({ data: "报告日志", display: "报告日志", inputcode: "BGRZ" });
                        this.reqstatOptiontable.push({ data: "-43", display: "无纸化", inputcode: "WZH" });
                        this.reqstatOptiontable.push({ data: "无纸化", display: "无纸化", inputcode: "WZH" });
                        console.log(this.reqstatOptiontable);
                    }
                })
                .catch((err) => {
                    this.$message.warning(err);
                });
        },
        async getdetails(row) {
            try {
                this.loading2 = true;
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS218",
                    method: "post",
                    data: {
                        action: "getdetails",
                        barcode: row.barcode,
                    },
                });

                if (res.details.length > 0) {
                    if (Number(row.req_groupid) > 0) {
                        this.tableData2 = res.details.filter((item) => item.req_groupid == row.req_groupid);
                    } else {
                        this.tableData2 = res.details;
                    }
                    this.$refs.xTable2.setCurrentRow(res.details[0]);
                } else {
                    this.$refs.xTable2.setCurrentRow(null);
                    this.tableData2 = [];
                }

                if (this.tab_showflag == "operatelog") {
                    this.QueryLog(this.key_barcode);
                } else {
                    this.getImage(row);
                }
                this.loading2 = false;
            } catch (e) {
                this.loading2 = false;
            }
        },
        async getImage(row) {
            this.LPicData = [];
            if (row.isPhoto != '0') {
                //获取图片
                const r = await this.$tool.request({
                    url: "LIS/LIS2/LIS218",
                    method: "post",
                    data: {
                        action: "getimage",
                        barcode: row.barcode,
                        rej_cnt: row.rej_cnt,
                    },
                });
                if (r.images.length > 0) {
                    r.images.forEach(element => {
                        this.LPicData.push(element.Item1);
                    });
                }
            }
        },
        RowClassName({ columnIndex, $rowIndex }) {
            return "row-blue";
        },
        querySearch(queryString, cb) {
            var restaurants = this.RejReaSonOption;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString) {
            return (restaurant) => {
                return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0;
            };
        },
        handleSelect(item) {
            this.txtmemo = item.value;
        },
        btn_showselother() {
            this.is_showselother = !this.is_showselother;
        },
        activecell({ row, columnIndex, column }) {
            return false;
        },
        deptchange(code, name) {
            this.txtdept = code;
            this.deptname = name;
            this.InitPage();
        },
        performdeptchange(code, name) {
            this.txtperformdept = code;
            this.performdeptname = name;
            this.InitPage();
        },
        wardchange(code, name) {
            this.txtward = code;
            this.wardname = name;
            this.InitPage();
        },
        userinfochange(code, name) {
            this.txtuser = code;
            this.username = name;
            this.InitPage();
        },
        hospitalchange(code, name) {
            this.txthoscode = code;
            this.hosname = name;
            this.InitPage();
        },
        labgroupchange1(code, name) {
            this.txtusergroup = code;
            this.usergroupname = name;
            this.InitPage();
        },
        labgroupchange2(code, name) {
            this.txtbarcodegroup = code;
            this.barcodegroupname = name;
            this.InitPage();
        },
        reqgroupchange(code, name) {
            this.txtreqgroup = code;
            this.reqgroupname = name;
            this.InitPage();
        },
        specimenchange(code, name) {
            this.txtspecimen = code;
            this.specimenname = name;
            this.InitPage();
        },
        // 查看照片
        // BtnLookPic() {
        //     this.$tool
        //         .request({
        //             url: "LIS/LIS2/LIS218",
        //             method: "post",
        //             data: {
        //                 action: "BtnLookPic",
        //                 barcode: this.key_barcode,
        //             },
        //         })
        //         .then((res) => {
        //             this.LPicName = res[0].Item1;
        //             this.LPicTime = res[0].Item2;
        //             this.LPicData = res[0].Item3;
        //             this.arrLPicData.push(res[0].Item3);
        //             this.PhotoDialogVisible = true;
        //         })
        //         .catch((e) => {
        //             console.log("error", e);
        //         });
        // },
        setExportColumn() {
            let allColumnList = [];
            this.$refs.xTable1.getColumns().forEach((element) => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property,
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    /* height: 100px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;*/
    left: 0;
    right: 0;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    /* height: 100px;*/
    overflow-x: auto;
    overflow-x: overlay;
}

.pagecenter {
    position: absolute;
    top: 125px;
    width: 100%;
    left: 0px;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 505px;
    overflow: auto;
}

.middle-right {
    position: absolute;
    height: 100%;
    width: 500px;
    right: 0px;
}

.table1style tr td {
    padding: 1px 2px 1px 2px;
}

::deep .myclass .vxe-table .vxe-footer--row.row-blue {
    background-color: #187;
    color: #fff;
}

.pagetopother {
    width: 100%;
    /*height: 125px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 929;*/

    left: 0;
    right: 0;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    /* height: 125px;*/
    overflow-x: auto;
    overflow-x: overlay;
}

.pagecenterother {
    position: absolute;
    top: 150px;
    width: 100%;
    left: 0px;
    bottom: 0px;
    overflow: auto;
}

::-webkit-scrollbar {
    width: 0px;
    height: 5px;
    border: 4px solid white;
}

::-webkit-scrollbar-thumb {
    background-color: #c1c1c1;
}

::-webkit-scrollbar-track {
    background-color: #f1f1f1;
}

/* Buttons */
::-webkit-scrollbar-button:single-button {
    background-color: #bbbbbb;
    display: block;
    border-style: solid;
    height: 5px;
    width: 5px;
}

/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
    margin-right: 2px;
    border-width: 4px 4px 4px 0;
    border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
    background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:decrement:hover {
    border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}

/* Right */
::-webkit-scrollbar-button:horizontal:increment {
    margin-left: 2px;
    border-width: 4px 0 4px 4px;
    border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
    background-color: #000000;
}

::-webkit-scrollbar-button:horizontal:increment:hover {
    border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}

.operation-list {
    float: right;
    margin-right: 5px;
    margin-bottom: 5px;
}

.demo-image__placeholder .block {
    top: 20px;
    width: 100%;
    padding: 20px 0;
    text-align: center;
    display: inline-block;
    /*box-sizing: border-box;*/
    vertical-align: top;
}

.block,
.demo-image__placeholder .block {
    width: 49%;
}

::v-deep .reportlogclass {
    color: blue;
    font-style: italic;
    font-size: 10px;
}
.table-bottom {
    position: absolute;
    left: 0px;
    bottom: 0%;
    z-index: 1;
    overflow: hidden;
    width: 100%;
}

</style>